<admintpl file="header" />
<style type="text/css">
    body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
</head>

<body>
  <div style="text-align:center;margin: 5px;">
      <input type="button" name="refresh"  class="btn btn-primary"  value="跑客位置刷新" onclick="pnRobRouteCounts()">
      跑客姓名：<input type="text" id="dispatch_name" name="dispatch_name" style="width:60px ">
       跑客电话：<input type="text" id="mobile" name="mobile"  style="width:60px ">
          <input type="button" name="refresh" class="btn btn-primary" value="搜索位置" onclick="pn_online_list()">
      </div>

  </div>
<div id="allmap">

</div>

<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=OkM4ci06ibVrimvizgsIWv0sjASIa7BK&s=1"></script>
<script type="text/javascript" src="https://api.map.baidu.com/library/DistanceTool/1.2/src/DistanceTool_min.js"></script>
<script type="text/javascript">

//ceshiceshi
    // 百度地图API功能
    var map = new BMap.Map("allmap");

    map.disableDoubleClickZoom(true);
    map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();

    var myIcon2 = new BMap.Icon("__PUBLIC__/images/start.png", new BMap.Size(35, 35));
    var myIcon3 = new BMap.Icon("__PUBLIC__/images/end.png", new BMap.Size(35, 35));

    pnRobRouteCounts();
    function pnRobRouteCounts() {
        $.ajax({
            type: "GET",
            async: true,
            url: "{:U('allpnroute')}",
            dataType: "json",
            success: function(data) {
                console.log("// 数据：");
                var pn_data = data.data;
//                console.log(pn_data);
                map.clearOverlays();
                for (var i = 0; i < pn_data.length; i ++) {
                    var company_id = pn_data[i]['company_id'];
//                    console.log(company_id);
                      var company_img = pn_data[i]['company_img'];
                    var myIcon = new BMap.Icon("__PUBLIC__/images/pn_company/"+company_img+".png", new BMap.Size(35, 35));
//                     console.log(company_img);
                    var pn_arr = pn_data[i]['data'];
//                    console.log(pn_arr);

                    if(pn_arr==null || pn_arr.length == 0 )
                            continue;
//                    console.log(pn_arr);
                    for(var j=0;j<pn_arr.length;j++){

                        var point = new BMap.Point( pn_arr[j]['lon'],pn_arr[j]['lat']);
//                        console.log(point);
                        var content = pn_arr[j]['dispatch_name']+","+pn_arr[j]['mobile']+"</br>"+pn_arr[j]['place_up_time']+"</br>执行中订单数:"+pn_arr[j]['order_num'];
                        var marker = new BMap.Marker(point, {icon: myIcon});
                        map.addOverlay(marker);
                        
                         if(pn_arr[j]["poisition"])
                        {
                            for(var k=0; k<pn_arr[j]["poisition"].length; k++)
                            {
                                //起点  
                                var marker2 = new BMap.Point(pn_arr[j]["poisition"][k]['send_longit'],pn_arr[j]["poisition"][k]['send_latit']);
                                var marker3 = new BMap.Marker(marker2, {icon: myIcon2});	
                                map.addOverlay(marker3);
                                addClickHandler(content,marker3);
                                //终点
                               var marker4 = new BMap.Point(pn_arr[j]["poisition"][k]['reci_longit'],pn_arr[j]["poisition"][k]['reci_latit']);
                               var marker5 = new BMap.Marker(marker4, {icon: myIcon3});	
                               map.addOverlay(marker5); 
                               addClickHandler(content,marker5);
                               
                               var p1 = new BMap.Point(pn_arr[j]["poisition"][k]['send_longit'],pn_arr[j]["poisition"][k]['send_latit']);
                               var p2 = new BMap.Point(pn_arr[j]["poisition"][k]['reci_longit'],pn_arr[j]["poisition"][k]['reci_latit']);

                               var walking = new BMap.WalkingRoute(map, {renderOptions:{map: map, autoViewport: true}});
	                       walking.search(p1, p2);
                            }
                        }
                        addClickHandler(content,marker);
                        var opts = {
                            position : point,    // 指定文本标注所在的地理位置
                            offset   : new BMap.Size(10, -50)    //设置文本偏移量
                        }
                        
                        var label = new BMap.Label(content, opts);  // 创建文本标注对象
                        label.setStyle({
                            color : "red",
                            fontSize : "10px",
                            height : "auto",
                            lineHeight : "auto",
                            fontFamily:"微软雅黑"
                        });
                        map.addOverlay(label);
                    }
                }
            }
        });
        var point = new BMap.Point(113.65,34.76);
        map.centerAndZoom(point, 13);
    }
    var opts = {
        width : 20,     // 信息窗口宽度
        height: 10,     // 信息窗口高度
        title : "跑客信息" , // 信息窗口标题
        enableMessage:true//设置允许信息窗发送短息
    };
    function addClickHandler(content,marker){
        marker.addEventListener("click",function(e){
            openInfo(content,e)}
        );
    }
    function openInfo(content,e){
        var p = e.target;
        var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
        var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象
        map.openInfoWindow(infoWindow,point); //开启信息窗口
    }
function  button_click()
    {
        pnRobRouteCounts();
    }
    function pn_online_list() {
        var name = $('#dispatch_name').val();
        var mobile = $('#mobile').val();

        layer.open({
            type: 2,
            title: '在线跑客信息列表',
            shadeClose: true,
            shade: 0.4,
            area: ['70%', '60%'],
//            content: '{:U("pn_online_list")}' //iframe的url
            content: '{:U("pn_online_list")}&name='+name+'&mobile='+mobile //iframe的url
        });
    }
</script>
</body>
</html>